package com.lwlk.zdk.controller.Statistics;

import com.alibaba.fastjson.JSONArray;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lwlk.zdk.enums.RetCode;
import com.lwlk.zdk.mapper.T.*;
import com.lwlk.zdk.mapper.pw.pwVehicleMapper;
import com.lwlk.zdk.mapper.sys.sysEnterpriseMapper;
import com.lwlk.zdk.mapper.wd.wdHfAreaMapper;
import com.lwlk.zdk.mapper.wd.wdIndustryDictionaryMapper;
import com.lwlk.zdk.model.Encapsulation.EncapsulationTired;
import com.lwlk.zdk.service.User.SysUserService;
import com.lwlk.zdk.util.*;
import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.*;


@RestController
@Transactional
@RequestMapping(value = "/statistics")
public class TiredStatisticsController {

    private final static String port = PropUtils.getString("ports");
    private final static String Ip = PropUtils.getString("Ip");
    private final static String clientCode = PropUtils.getString("clientCode");

    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    TDisEnterpriseMapper tDisEnterpriseMapper;
    @Autowired
    TDisPlatformMapper tDisPlatformMapper;
    @Autowired
    TDisVehicleMapper tDisVehicleMapper;
    @Autowired
    TDisDictionaryMapper disDictionaryMapper;
    @Autowired
    TRegionMapper tRegionMapper;
    @Autowired
    TDisMismatchVehicleMapper disMismatchVehicleMapper;





    /*
    * eids:企业id。不传值代表查询全部企业，若选只能选择一个企业
    * */
    @ApiOperation(value = "疲劳驾驶统计接口")
    @RequestMapping(value = "/alarmStatistic/fatigue",method = RequestMethod.POST)
    public JSONObject fatigue(String year,String month,String eid,String regionCode){
       try {
           Map map=new HashMap();
           map.put("year",year);//必传 年份
           map.put("month",month);//必传 月份
           map.put("eid",eid);//企业id。不传值代表查询全部企业，若选只能选择一个企业
           map.put("regionCode",regionCode);//必传 登录用户所属机构所在地行政区划代码
           Set<String> set = map.keySet();
           Iterator<String> it = set.iterator();
           while (it.hasNext()) {
               String str = it.next();
               if(map.get(str)==null || map.get(str) =="null"|| map.get(str)==""){
                   map.remove(str);
                   set = map.keySet();
                   it = set.iterator();
               }
           }
           String url="http://"+Ip+":"+port+"/dis/statistic/alarmStatistic/fatigue";
           Map<String,String>headMap=new HashMap<>();
           headMap.put("clientCode",clientCode);
           String result=HttpClientUtils.doPost(url,headMap,map);
           JSONObject json= JSONObject.parseObject(result);
           JSONObject jo=json.getJSONObject("result");
           if (jo==null){
               String message="{\"msg\":\"接口执行成功\",\"result\":{\"data\":{\"day29\":0,\"day28\":0,\"day27\":0,\"day26\":0,\"day14\":0,\"day13\":0,\"day12\":0,\"day11\":0,\"day10\":0,\"day31\":0,\"day30\":0,\"day19\":0,\"day18\":0,\"day17\":0,\"day16\":0,\"day15\":0,\"day25\":0,\"day24\":0,\"day8\":0,\"day23\":0,\"day9\":0,\"day22\":0,\"day6\":0,\"day21\":0,\"day7\":0,\"day20\":0,\"day4\":0,\"day5\":0,\"day2\":0,\"day3\":0,\"day1\":0},\"month\":\"0\",\"years\":\"0\"},\"code\":1001}";
               return JSONObject.parseObject(message);
           }
           Integer eId=null;
           if (jo.getString("eid")==null){
               eId=null;
           }else {
               eId=Integer.parseInt(jo.getString("eid"));
           }

           String mon=jo.getString("month");//报警类型
           String clientCode=jo.getString("clientCode");
           String years=jo.getString("year");
           jo.remove("month");
           jo.remove("clientCode");
           jo.remove("year");
           jo.remove("id");
           jo.remove("eid");
           for (int i = 1; i < jo.size(); i++) {
               String key= String.valueOf(jo.get("day"+i));
               jo.remove("day"+i);
               jo.put(String.valueOf(i),key);

           }
           JSONObject js=new JSONObject();
           js.put("data",jo);
           json.remove("result");
           js.put("years",years);
           js.put("month",mon);
           js.put("clientCode",clientCode);
           js.put("data",js.get("data"));
           String enterpriseName=tDisEnterpriseMapper.selectByEid(eId);
           js.put("enterpriseName",enterpriseName);
           json.put("result",js);
           return json;
       }catch (Exception e){
           e.printStackTrace();
       }
        return null;
    }

    @ApiOperation(value = "超速次数统计接口")
    @RequestMapping(value = "/overspeed",method = RequestMethod.POST)
    public JSONObject overspeed(String year,String month,String eid,String areaCode){
    try {

        Map map=new HashMap();
        map.put("year",year);
        map.put("month",month);
        map.put("eid",eid);
        map.put("regionCode",areaCode);
        Set<String> set = map.keySet();
        Iterator<String> it = set.iterator();
        while (it.hasNext()) {
            String str = it.next();
            if(map.get(str)==null || map.get(str) =="null"|| map.get(str)==""){
                map.remove(str);
                set = map.keySet();
                it = set.iterator();
            }
        }
        Map<String,String>headMap=new HashMap<>();
        headMap.put("clientCode",clientCode);
        String url="http://"+Ip+":"+port+"/dis/statistic/alarmStatistic/overspeed";
        String result=HttpClientUtils.doPost(url,headMap,map);
        JSONObject json= JSONObject.parseObject(result);
        JSONObject jo=json.getJSONObject("result");
        if (jo==null){
            String message="{\"msg\":\"接口执行成功\",\"result\":{\"data\":{\"day29\":0,\"day28\":0,\"day27\":0,\"day26\":0,\"day14\":0,\"day13\":0,\"day12\":0,\"day11\":0,\"day10\":0,\"day31\":0,\"day30\":0,\"day19\":0,\"day18\":0,\"day17\":0,\"day16\":0,\"day15\":0,\"day25\":0,\"day24\":0,\"day8\":0,\"day23\":0,\"day9\":0,\"day22\":0,\"day6\":0,\"day21\":0,\"day7\":0,\"day20\":0,\"day4\":0,\"day5\":0,\"day2\":0,\"day3\":0,\"day1\":0},\"month\":\"0\",\"years\":\"0\"},\"code\":1001}";
            return JSONObject.parseObject(message);
        }
        JSONObject js=new JSONObject();
        if (jo.getString("eid")==null){
            js.put("enterpriseName",null);
        }else {
            Integer eids=Integer.parseInt(jo.getString("eid"));
            String enterpriseName=tDisEnterpriseMapper.selectByEid(eids);
        }

        String mon=jo.getString("month");//报警类型
        String clientCode=jo.getString("clientCode");
        String years=jo.getString("year");
        jo.remove("month");
        jo.remove("clientCode");
        jo.remove("year");
        jo.remove("id");
        jo.remove("eid");
        for (int i = 1; i < jo.size(); i++) {
            String key= String.valueOf(jo.get("day"+i));
            jo.remove("day"+i);
            jo.put(String.valueOf(i),key);

        }
        js.put("data",jo);
        json.remove("result");
        js.put("years",years);
        js.put("month",mon);
        js.put("clientCode",clientCode);
        js.put("data",js.get("data"));
        json.put("result",js);
        return json;
    }catch (Exception e){
        e.printStackTrace();
    }
    return null;
    }


    @ApiOperation(value = "报警时段数据统计")
    @RequestMapping(value = "/period",method = RequestMethod.POST)
    public JSONObject getPeriod(String date,String alarmTypes,String areaCode){
      try {
          Map map=new HashMap();
          map.put("date",date);//必选 日期,不能选择当天日期
          map.put("alarmTypes",alarmTypes);//必选 报警类型,多个id以英文逗号分隔
          map.put("regionCode",areaCode);//必选 登录用户所属机构所在地行政区划代码
          Map<String,String>headMap=new HashMap<>();
          headMap.put("clientCode",clientCode);
          String url="http://"+Ip+":"+port+"/dis/statistic/alarmStatistic/period";
          String result=HttpClientUtils.doPost(url,headMap,map);
          JSONObject json= JSONObject.parseObject(result);
          JSONArray jsonArray=json.getJSONArray("result");
          if (jsonArray==null) {
              String message="{\"msg\":\"接口执行成功\",\"result\":[{\"t1\":0,\"t2\":0,\"t3\":0,\"t4\":0,\"t5\":0,\"t6\":0,\"t7\":0,\"t8\":0,\"t9\":0,\"t10\":0,\"t11\":0,\"t12\":0,\"t13\":0,\"t14\":0,\"t15\":0,\"t16\":0,\"t17\":0,\"t18\":0,\"t19\":0,\"t20\":0,\"t21\":0,\"t22\":0,\"t23\":0,\"t24\":0}],\"code\":1001}";
              return JSONObject.parseObject(message);

          }
          for (int i = 0; i < jsonArray.size(); i++) {
              JSONObject jsonObject=jsonArray.getJSONObject(i);
              String type=jsonObject.getString("type");//报警类型
              String time=jsonObject.getString("time");
              String total=jsonObject.getString("total");
              jsonObject.remove("type");
              jsonObject.remove("time");
              jsonObject.remove("id");
              jsonObject.remove("total");
              String vehicleAlarm=disDictionaryMapper.selectAlarmType(type);
              JSONObject jsonObject1=new JSONObject();
              jsonObject1.put("vehicleAlarm",vehicleAlarm);
              jsonObject1.put("type",type);
              jsonObject1.put("time",time);
              jsonObject1.put("total",total);
              jsonObject1.put("data",jsonObject);
              jsonArray.set(i,jsonObject1);
          }
          return json;
      }catch (Exception e){
          e.printStackTrace();
      }
      return null;
    }

    //==========驾驶异常:查询一段时间内驾驶异常报警详情================
    /*
    *warnLevel:报警等级,一级：1，二级2
    * warnType:报警类型,查询字典表
    * vIds:车辆id，多个英文逗号分隔
    * driverIds:驾驶员id，多个英文逗号分隔
     * */
   /* @RequestMapping(value = "/activeSafetyDetails/dsm",method = RequestMethod.GET)
    public JSONObject dsm(String clientCode,Date startTime,Date endTime,Integer[] driverIds,Integer[] vehicleIds,String warnLevel,String warnType){
        try {
            Map map=new HashMap();
            map.put("clientCode",clientCode);
            map.put("startTime",startTime);
            map.put("endTime",endTime);
            map.put("driverIds",driverIds);
            map.put("vehicleIds",vehicleIds);
            map.put("warnLevel",warnLevel);
            map.put("warnType",warnType);
            String url="http://"+Ip+":"+port+"/dis/statistics/activeSafetyDetails/dsm";
            String result=HttpClientUtil.doGet(url,map);
            JSONObject json= JSONObject.parseObject(result);
            return json;
        }catch (Exception e){
            e.printStackTrace();
        }
           return null;
    }*/


    @ApiOperation(value = "车辆报警")
    @RequestMapping(value = "/vehicleAlarm/info",method = RequestMethod.GET)
    /*
    * alarmType:报警类型
    * */
    public JSONObject info(String startTime,String endTime,String eIds,String vIds,String admdivcodes,String alarmType,String limit,String page){
        try {
            Map map=new HashMap();
            map.put("startTime",startTime);//必选 开始查询时间yyyy-MM-dd HH:mm:ss
            map.put("endTime",endTime);//必选 结束查询时间yyyy-MM-dd HH:mm:ss
            map.put("enterpriseIds",eIds);//企业id，多个英文逗号分隔
            map.put("vehicleIds",vIds);//车辆id，多个英文逗号分隔
            map.put("admdivcode",admdivcodes);//行政区划编码，多个英文逗号分隔
            map.put("alarmType",alarmType);//报警类型
            map.put("limit",limit);//页面记录数，默认10
            map.put("page",page);//页码，默认值为1
            Set<String> set = map.keySet();
            Iterator<String> it = set.iterator();
            while (it.hasNext()) {
                String str = it.next();
                if(map.get(str)==null || map.get(str) =="null"|| map.get(str)==""){
                    map.remove(str);
                    set = map.keySet();
                    it = set.iterator();
                }
            }
            Map<String,String>headMap=new HashMap<>();
            headMap.put("clientCode",clientCode);
            String url="http://"+Ip+":"+port+"/dis/statistics/vehicleAlarm/info";
            String result=HttpClientUtils.doGet(url,headMap,map);
            JSONObject json= JSONObject.parseObject(result);
            JSONObject jo=json.getJSONObject("result");
            JSONArray jsonArray=json.getJSONArray("list");
            if (jsonArray==null){
                return json;
            }
            for (int i = 0; i < jsonArray.size(); i++) {
                JSONObject jsonObject=jsonArray.getJSONObject(i);
                Integer vId=Integer.parseInt(jsonObject.getString("vId"));//车辆id
                Integer eId=Integer.parseInt(jsonObject.getString("eId"));//企业id
                String oId=jsonObject.getString("oId");//机构id
                String areaCode=tRegionMapper.selectByoId(Integer.parseInt(oId));

                String aType=jsonObject.getString("alarmType");//报警类型
                //String vehicleAlarm=wdIndustryDictionaryMapper.selectAlarmType(aType);
                //String enterpriseName=sysEnterpriseMapper.selectByEid(eId);//企业名称
                String enterpriseName=tDisEnterpriseMapper.selectByEid(eId);
                //String vehicleName=pwVehicleMapper.selectByVid(vId);//车辆名称
                String vehicleName=tDisVehicleMapper.selectByVid(vId);
                jsonObject.put("enterpriseName",enterpriseName);
                jsonObject.put("vehicleName",vehicleName);
                jsonObject.put("administrationName",areaCode);
            }
            return json;
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }

    //===========报警列表=============
    @ApiOperation(value = "报警列表")
    @RequestMapping(value = "/vehicleAlarm/list",method = RequestMethod.GET)
    public JSONObject list(String startTime,String endTime,String eIds,String driverIds,String alarmType,String limit,String page,String regionCode,String platformId){
        try {
            Map map=new HashMap();
            map.put("startTime",startTime);//必选 开始查询时间yyyy-MM-dd HH:mm:ss
            map.put("endTime",endTime);//必选 结束查询时间yyyy-MM-dd HH:mm:ss
            map.put("vIds",eIds);//企业id，多个英文逗号分隔
            map.put("driverIds",driverIds);//驾驶员id，多个英文逗号分隔
            map.put("alarmType",alarmType);//报警类型
            map.put("admdivcode",regionCode);//
            map.put("userId",platformId);//必传 平台id
            map.put("limit",limit);//页面记录数，默认10
            map.put("page",page);//页码，默认值为1
            Set<String> set = map.keySet();
            Iterator<String> it = set.iterator();
            while (it.hasNext()) {
                String str = it.next();
                if(map.get(str)==null || map.get(str) =="null"|| map.get(str)==""){
                    map.remove(str);
                    set = map.keySet();
                    it = set.iterator();
                }
            }
            Map<String,String>headMap=new HashMap<>();
            headMap.put("clientCode",clientCode);
            String url="http://"+Ip+":"+port+"/dis/statistics/vehicleAlarm/list";
            String result=HttpClientUtils.doGet(url,headMap,map);
            JSONObject json= JSONObject.parseObject(result);
            return json;
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }


    @ApiOperation(value = "车辆报警:查询某车辆报警报警总数")
    @RequestMapping(value = "/totalDetails",method = RequestMethod.GET)
    public JSONObject totalDetails(String date,String vId,String limit,String page){
        try {
            Map map=new HashMap();
            map.put("date",date);//必传 查询日期yyyy-MM-dd
            map.put("vId",vId);//必传 车辆id
            map.put("limit",limit);//页面记录数，默认值10
            map.put("page",page);//页码，默认值1
            Set<String> set = map.keySet();
            Iterator<String> it = set.iterator();
            while (it.hasNext()) {
                String str = it.next();
                if(map.get(str)==null || map.get(str) =="null"|| map.get(str)==""){
                    map.remove(str);
                    set = map.keySet();
                    it = set.iterator();
                }
            }
            String url="http://"+Ip+":"+port+"/dis/v1/statistics//totalDetails";
            Map<String,String>headMap=new HashMap<>();
            headMap.put("clientCode",clientCode);
            String result=HttpClientUtils.doGet(url,headMap,map);
            JSONObject json= JSONObject.parseObject(result);
            JSONObject jo=json.getJSONObject("result");
            JSONArray jsonArray=json.getJSONArray("list");
            if (jsonArray==null){
                return json;
            }
            for (int i = 0; i < jsonArray.size(); i++) {
                JSONObject jsonObject=jsonArray.getJSONObject(i);
                String aType=jsonObject.getString("alarmType");//报警类型
                //String vehicleAlarm=wdIndustryDictionaryMapper.selectAlarmType(aType);
                //jsonObject.put("administrationName",areaCode);
            }
            return json;
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }


    @ApiOperation(value = "报警统计")
    @RequestMapping(value = "/alarmType/alarm",method = RequestMethod.GET)
    public JSONObject alarmStatistics(String startDate,String endDate,String limit,String page,String vehicleNumber,String regionCode){
       try {
           if (vehicleNumber!=null && vehicleNumber.length() < 3 && !vehicleNumber.equals("")) {
               String list = "{\"code\":1009,\"msg\":\"请输入车牌号不少于3位\"}";
               return JSONObject.parseObject(list);
           }
           String vIdlist="";
           String vIds="";
           if (vehicleNumber!=null && vehicleNumber.equals("")==false){
               List<Map> vehicleNumberList=tDisVehicleMapper.selectVehicleId(vehicleNumber.toUpperCase());
               if (vehicleNumberList.size()>0){
                   for (int i = 0; i < vehicleNumberList.size(); i++) {
                       vIdlist=vIdlist+vehicleNumberList.get(i).get("vehicle_id")+",";
                   }
                   vIds=StringUtils.join(vIdlist.split(","),",");
               }else {
                   String list="{\"code\":1001,\"msg\":\"接口执行成功\",\"result\":{\"currPage\":1,\"list\":[],\"pageSize\":0,\"totalCount\":0,\"totalPage\":0}}";
                   return JSONObject.parseObject(list);
               }
           }
           Map map=new HashMap();
           map.put("startDate",startDate);//必传 开始查询日期yyyy-MM-dd
           map.put("endDate",endDate);//必传 结束查询时间yyyy-MM-dd
           //map.put("vIds",vIds);//车辆id,多个id以逗号分隔
           map.put("limit",limit);//必传 页面记录数，默认为10
           map.put("regionCode",regionCode);//必传 用户行政区划编码
           map.put("page",page);//页码 必传，默认为1
           Set<String> set = map.keySet();
           Iterator<String> it = set.iterator();
           while (it.hasNext()) {
               String str = it.next();
               if(map.get(str)==null || map.get(str) =="null"|| map.get(str)==""){
                   map.remove(str);
                   set = map.keySet();
                   it = set.iterator();
               }
           }
           JSONObject jso = new JSONObject();
           String body=jso.toJSONString(vIds);
           String path = "/dis/v1/statistics/alarmType/alarm";
           Map<String,String>headMap=new HashMap<>();
           headMap.put("clientCode",clientCode);
           String result=HttpClientUtils.doPostTestFour(path,headMap, map,body);
           JSONObject json= JSONObject.parseObject(result);
           JSONObject jo=json.getJSONObject("result");
           if (jo==null){
               return json;
           }
           JSONArray jsonArray=jo.getJSONArray("list");

           for (int i = 0; i < jsonArray.size(); i++) {
               JSONObject jsonObject=jsonArray.getJSONObject(i);
               Integer vId=Integer.parseInt(jsonObject.getString("vId"));//车辆id
               String vehicleName=tDisVehicleMapper.selectByVid(vId);
               jsonObject.put("vehicleName",vehicleName);
           }
           return json;

       }catch (Exception e){
           e.printStackTrace();
       }
       return null;
    }


    @ApiOperation(value = "报警详情-车辆动态数据分析")
    @RequestMapping(value = "/vehicleDetails",method = RequestMethod.GET)
    public JSONObject vehicleDetails(String startTime,String endTime,String vId,String warnType,String limit,String page){
        Map map=new HashMap();
        map.put("startTime",startTime);//必选 开始查询时间yyyy-MM-dd
        map.put("endTime",endTime);//必选 结束查询时间yyyy-MM-dd
        map.put("vId",vId);//必选 车辆id
        map.put("warnType",warnType);//必选 报警类型
        map.put("limit",limit);//页面记录数
        map.put("page",page);//页码
        Set<String> set = map.keySet();
        Iterator<String> it = set.iterator();
        while (it.hasNext()) {
            String str = it.next();
            if(map.get(str)==null || map.get(str) =="null"|| map.get(str)==""){
                map.remove(str);
                set = map.keySet();
                it = set.iterator();
            }
        }
        String url="http://"+Ip+":"+port+"/dis/statistics/activeSafetyDetails/vehicleDetails";
        Map<String,String>headMap=new HashMap<>();
        headMap.put("clientCode",clientCode);
        String result=HttpClientUtils.doGet(url,headMap,map);
        JSONObject json= JSONObject.parseObject(result);
        return json;
    }


    @ApiOperation(value = "报警详情-企业动态数据分析")
    @RequestMapping(value = "/activeSafetyDetails/enterpriseDetails",method = RequestMethod.GET)
    public JSONObject enterpriseDetails(String startTime,String endTime,String eId,String warnType,String limit,String page){
        Map map=new HashMap();
        map.put("startTime",startTime);//必选 开始查询时间yyyy-MM-dd
        map.put("endTime",endTime);//必选 结束查询时间yyyy-MM-dd
        map.put("eId",eId);//必选 企业id
        map.put("warnType",warnType);//必选 报警类型
        map.put("limit",limit);//页面记录数
        map.put("page",page);//页码
        Set<String> set = map.keySet();
        Iterator<String> it = set.iterator();
        while (it.hasNext()) {
            String str = it.next();
            if(map.get(str)==null || map.get(str) =="null"|| map.get(str)==""){
                map.remove(str);
                set = map.keySet();
                it = set.iterator();
            }
        }
        String url="http://"+Ip+":"+port+"/dis/statistics/activeSafetyDetails/enterpriseDetails";
        Map<String,String>headMap=new HashMap<>();
        headMap.put("clientCode",clientCode);
        String result=HttpClientUtils.doGet(url,headMap,map);
        JSONObject json= JSONObject.parseObject(result);
        return json;
    }


    @ApiOperation(value = "报警详情-驾驶员动态数据分析")
    @RequestMapping(value = "/driverDetails",method = RequestMethod.GET)
    public JSONObject driverDetails(String startTime,String endTime,String driverId,String warnType,String limit,String page){
        Map map=new HashMap();
        map.put("startTime",startTime);//必选 开始查询时间yyyy-MM-dd
        map.put("endTime",endTime);//必选 结束查询时间yyyy-MM-dd
        map.put("driverId",driverId);//必选 驾驶员id
        map.put("warnType",warnType);//必选 报警类型
        map.put("limit",limit);//页面记录数
        map.put("page",page);//页码
        Set<String> set = map.keySet();
        Iterator<String> it = set.iterator();
        while (it.hasNext()) {
            String str = it.next();
            if(map.get(str)==null || map.get(str) =="null"|| map.get(str)==""){
                map.remove(str);
                set = map.keySet();
                it = set.iterator();
            }
        }
        String url="http://"+Ip+":"+port+"/dis/statistics/activeSafetyDetails/driverDetails";
        Map<String,String>headMap=new HashMap<>();
        headMap.put("clientCode",clientCode);
        String result=HttpClientUtils.doGet(url,headMap,map);
        JSONObject json= JSONObject.parseObject(result);
        return json;
    }




    @ApiOperation(value = "轨迹分析接口")
    @RequestMapping(value = "/track",method = RequestMethod.POST)
    public JSONObject getTrack(EncapsulationTired encapsulationTired, String eid, String pName, String vNumber){
        if (vNumber!=null && vNumber.length() < 3 && !vNumber.equals("")) {
            String list = "{\"code\":1009,\"msg\":\"请输入车牌号不少于3位\"}";
            return JSONObject.parseObject(list);
        }
        String pIdList="";
        String pIds=null;
        if (pName!=null&& pName.equals("")==false){
            List<Map> pIdsList=tDisPlatformMapper.selectPlatformIdsList(pName);
            if (pIdsList.size()>0){
                for (int i = 0; i < pIdsList.size(); i++) {
                    pIdList=pIdList+pIdsList.get(i).get("platform_id")+",";
                }
                pIds=StringUtils.join(pIdList.split(","),",");
            }else {
                String list="{\"code\":1001,\"msg\":\"接口执行成功\",\"result\":{\"currPage\":1,\"list\":[],\"pageSize\":0,\"totalCount\":0,\"totalPage\":0}}";
                return JSONObject.parseObject(list);
            }
        }
        Map map=new HashMap();
        //map.put("nanos",nanos);
/*        map.put("enterpriseIds",eIds);//企业id，多个id以英文逗号分隔
        map.put("platformIds",pIds);//平台id，多个id以英文逗号分隔
        map.put("vehicleIds",vIds);//车辆id，多个id以英文逗号分隔
        map.put("startTime",startTime);//开始时间
        map.put("endTime",endTime);//结束时间
        map.put("regionCode",regionCode);//必选 登录用户所属行政区划代码
        map.put("pageNum",pageNum);//必选 页面记录条数
        map.put("pageSize",pageSize);//必选 页码*/
        if (vNumber!=null) {
            vNumber = vNumber.toUpperCase();
        }
        encapsulationTired.setVnumber(vNumber);
        encapsulationTired.setEnterpriseIds(eid);
        encapsulationTired.setPlatformIds(pIds);
        String path="/dis/v1/track/statistics";
        Map<String,String>headMap=new HashMap<>();
        headMap.put("clientCode",clientCode);
        JSONObject jsonString = new JSONObject();
        String body= jsonString.toJSONString(encapsulationTired);;
        String result=HttpClientUtils.doPostTestThree(path,headMap,map,body);
        JSONObject json= JSONObject.parseObject(result);
        JSONObject jo=json.getJSONObject("result");
        if (jo==null){
            return json;
        }
        JSONArray jsonArray=jo.getJSONArray("list");
        for (int i = 0; i < jsonArray.size(); i++) {
            JSONObject jsonObject=jsonArray.getJSONObject(i);
            Integer vId=Integer.parseInt(jsonObject.getString("vehicleId"));//车辆id
            Integer pId=Integer.parseInt(jsonObject.getString("platformId"));//平台id
            Integer eIds=Integer.parseInt(jsonObject.getString("enterpriseId"));//企业id
            Integer timeSpan=Integer.parseInt(jsonObject.getString("duration"));//持续时长(min)
            //String enterpriseName=sysEnterpriseMapper.selectByEid(eId);//企业名称
            String enterpriseName=tDisEnterpriseMapper.selectByEid(eIds);
            //String platformName=sysUserService.selectBypId(pId);//平台名称
            String platformName=tDisPlatformMapper.selectpId(pId);
            //String vehicleName=pwVehicleMapper.selectByVid(vId);//车辆名称
            List<Map>vehicleAndColor=tDisVehicleMapper.selectVnameAndColor(vId);
            jsonObject.put("enterpriseName",enterpriseName);
            jsonObject.put("platformName",platformName);
            double timeSpans = new BigDecimal((float)timeSpan/60).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
            jsonObject.put("duration",timeSpans);
            if (vehicleAndColor.size()>0){
                jsonObject.put("vehicleNumber",vehicleAndColor.get(0).get("vehicle_number"));
                jsonObject.put("vehicleLicenseColor",vehicleAndColor.get(0).get("item_name"));
            }else {
                jsonObject.put("vehicleNumber",null);
                jsonObject.put("vehicleLicenseColor",null);
            }
        }
        return json;
    }


    @ApiOperation(value = "根据车辆id和高级选项查询指定车辆历史位置，卫星定位通用监控管理-车辆树点击车辆-点击【轨迹】-轨迹列表-不分页")
    @RequestMapping(value = "/track_vehicleId_with_option",method = RequestMethod.GET)
    public JSONObject getOption(String page,String size,String vehicleId,String startTime,String endTime){
        Map map=new HashMap();
        map.put("pageNum",page);
        map.put("pageSize",size);
        map.put("inout","0");
        map.put("vehicleId",vehicleId);//必传 车辆id
        map.put("startTime",startTime);//必传 查询起始时间，开始结束时间跨度限制为24h
        map.put("endTime",endTime);//必传 查询结束时间
        Set<String> set = map.keySet();
        Iterator<String> it = set.iterator();
        while (it.hasNext()) {
            String str = it.next();
            if(map.get(str)==null || map.get(str) =="null"|| map.get(str)==""){
                map.remove(str);
                set = map.keySet();
                it = set.iterator();
            }
        }
        String url="http://"+Ip+":"+port+"/dis/vehicle/track_vehicleId_with_option";
        Map<String,String>headMap=new HashMap<>();
        headMap.put("clientCode",clientCode);
        String result=HttpClientUtils.doGet(url,headMap,map);
        JSONObject json= JSONObject.parseObject(result);
        JSONArray jsonArray=json.getJSONArray("result");
        for (int i = 0; i < jsonArray.size(); i++) {
            JSONObject jsonObject=jsonArray.getJSONObject(i);
            Integer vId=Integer.parseInt(jsonObject.getString("vehicleId"));//车辆id
            List<Map<String,Object>>vehicleList=tDisVehicleMapper.selectPNameAndEname(vId);
            jsonObject.put("vehicleNumber",vehicleList.get(0).get("vehicleNumber"));
            jsonObject.put("vehicleNumberColor",vehicleList.get(0).get("vehicleNumberColor"));
            jsonObject.put("regionName",vehicleList.get(0).get("regionName"));
        }
        return json;
    }


    @ApiOperation(value = "连通性统计接口")
    @RequestMapping(value = "/connectStatistic/list",method = RequestMethod.GET)
    public JSONObject connectStatistic(String startTime,String endTime,String limit,String page,String pName){
        String pIdList="";
        String pIds=null;
        if (pName!=null && pName.equals("")==false){
            List<Map> pIdsList=tDisPlatformMapper.selectPlatformIdsList(pName);
            if (pIdsList.size()>0){
                for (int i = 0; i < pIdsList.size(); i++) {
                    pIdList=pIdList+pIdsList.get(i).get("platform_id")+",";
                }
                pIds=StringUtils.join(pIdList.split(","),",");
            }else {
                String list="{\"code\":1001,\"msg\":\"接口执行成功\",\"result\":{\"currPage\":1,\"list\":[],\"pageSize\":0,\"totalCount\":0,\"totalPage\":0}}";
                return JSONObject.parseObject(list);
            }
        }
      Map map=new HashMap();
      map.put("startTime",startTime);//查询开始时间yyyy-MM-dd HH:mm:ss
      map.put("endTime",endTime);//查询结束时间yyyy-MM-dd HH:mm:ss
      map.put("pIds",pIds);//平台id,多个id以逗号分隔
      map.put("limit",limit);//页面记录数，默认为10
      map.put("page",page);//页码，默认为1
        Set<String> set = map.keySet();
        Iterator<String> it = set.iterator();
        while (it.hasNext()) {
            String str = it.next();
            if(map.get(str)==null || map.get(str) =="null"|| map.get(str)==""){
                map.remove(str);
                set = map.keySet();
                it = set.iterator();
            }
        }
        Map<String,String>headMap=new HashMap<>();
        headMap.put("clientCode",clientCode);
      String url="http://"+Ip+":"+port+"/dis/v1/statistics/connectStatistic/list";
      String result=HttpClientUtils.doGet(url,headMap,map);
        JSONObject json= JSONObject.parseObject(result) ;
        JSONObject jo=json.getJSONObject("result");
        JSONArray jsonArray=jo.getJSONArray("list");
        if (jsonArray==null){
            return json;
        }
        for (int i = 0; i < jsonArray.size(); i++) {
            JSONObject jsonObject=jsonArray.getJSONObject(i);
            BigDecimal onlineCount=BigDecimal.valueOf(Long.parseLong(jsonObject.getString("onlineCount")));//在线次数
            BigDecimal offlineCount=BigDecimal.valueOf(Long.parseLong(jsonObject.getString("offlineCount")));//离线次数
            Integer pId=Integer.parseInt(jsonObject.getString("pId"));//平台id
            //String platformName=sysUserService.selectBypId(pId);//平台名称
            String platformName=tDisPlatformMapper.selectpId(pId);
            DecimalFormat df = new DecimalFormat("0.00%");
            String connectedRate=df.format(onlineCount.divide(onlineCount.add(offlineCount),2,BigDecimal.ROUND_HALF_UP));//连通率
            jsonObject.put("connectedRate",connectedRate);
            jsonObject.put("platformName",platformName);
        }
        return json;
    }


    @ApiOperation(value = "超速统计接口")
    @RequestMapping(value = "/overspeed/info",method = RequestMethod.GET)
    public JSONObject getInfo(String startTime,String endTime,String eName,String pName,String vNumber,String limit,String page){
        String eIdsList="";
        String vIdlist="";
        String pIdList="";
        String eIds=null;
        String vIds=null;
        String pIds=null;
        if (eName!=null && eName.equals("")==false){
            List<Map> eIdsLists = tDisEnterpriseMapper.selectEnterpriseNameList(eName);
            if (eIdsLists.size()>0){
                for (int i = 0; i < eIdsLists.size(); i++) {
                    eIdsList = eIdsList + eIdsLists.get(i).get("enterprise_id")+",";
                }
                eIds=StringUtils.join(eIdsList.split(","),",");
            }else {
                String list="{\"code\":1001,\"msg\":\"接口执行成功\",\"result\":{\"currPage\":1,\"list\":[],\"pageSize\":0,\"totalCount\":0,\"totalPage\":0}}";
                return JSONObject.parseObject(list);
            }
        }
        if (vNumber!=null && vNumber.equals("")==false){
            List<Map> vehicleNumberList=tDisVehicleMapper.selectVehicleId(vNumber);
            if (vehicleNumberList.size()>0){
                for (int i = 0; i < vehicleNumberList.size(); i++) {
                    vIdlist=vIdlist+vehicleNumberList.get(i).get("vehicle_id")+",";
                }
                vIds=StringUtils.join(vIdlist.split(","),",");
            }else {
                String list="{\"code\":1001,\"msg\":\"接口执行成功\",\"result\":{\"currPage\":1,\"list\":[],\"pageSize\":0,\"totalCount\":0,\"totalPage\":0}}";
                return JSONObject.parseObject(list);
            }
        }
        if (pName!=null&& pName.equals("")==false){
            List<Map> pIdsList=tDisPlatformMapper.selectPlatformIdsList(pName);


            if (pIdsList.size()>0){
                for (int i = 0; i < pIdsList.size(); i++) {
                    pIdList=pIdList+pIdsList.get(i).get("platform_id")+",";
                }
                pIds=StringUtils.join(pIdList.split(","),",");
            }else {
                String list="{\"code\":1001,\"msg\":\"接口执行成功\",\"result\":{\"currPage\":1,\"list\":[],\"pageSize\":0,\"totalCount\":0,\"totalPage\":0}}";
                return JSONObject.parseObject(list);
            }
        }
        Map map=new HashMap();
        map.put("startTime",startTime);//开始时间yyyy-MM-dd HH:mm:ss
        map.put("endTime",endTime);//结束时间yyyy-MM-dd HH:mm:ss
        map.put("pIds",pIds);//平台id,多个id以逗号分隔
        map.put("eIds",pIds);//企业id,多个id以逗号分隔
        map.put("vIds",pIds);//车辆id,多个id以逗号分隔
        map.put("limit",limit);//页面记录数，默认值为10
        map.put("page",page);//页码，默认值为1
        Set<String> set = map.keySet();
        Iterator<String> it = set.iterator();
        while (it.hasNext()) {
            String str = it.next();
            if(map.get(str)==null || map.get(str) =="null"|| map.get(str)==""){
                map.remove(str);
                set = map.keySet();
                it = set.iterator();
            }
        }
        Map<String,String>headMap=new HashMap<>();
        headMap.put("clientCode",clientCode);
        String url="http://"+Ip+":"+port+"/dis/v1/statistics/overspeed/info";
        String result=HttpClientUtil.doGet(url,map);
        JSONObject json= JSONObject.parseObject(result);
        JSONObject jo=json.getJSONObject("result");
        JSONArray jsonArray=jo.getJSONArray("list");
        if (jsonArray==null){
            return json;
        }
        for (int i = 0; i < jsonArray.size(); i++) {
            JSONObject jsonObject=jsonArray.getJSONObject(i);
            Integer vId=Integer.parseInt(jsonObject.getString("vId"));//车辆id
            Integer pId=Integer.parseInt(jsonObject.getString("pId"));//平台id
            Integer eId=Integer.parseInt(jsonObject.getString("eId"));//企业id
            Integer timeSpan=Integer.parseInt(jsonObject.getString("timeSpan"));//持续时长(min)
            //String enterpriseName=sysEnterpriseMapper.selectByEid(eId);//企业名称
            String enterpriseName=tDisEnterpriseMapper.selectByEid(eId);
            //String platformName=sysUserService.selectBypId(pId);//平台名称
            String platformName=tDisPlatformMapper.selectpId(pId);
            //String vehicleName=pwVehicleMapper.selectByVid(vId);//车辆名称
            String vehicleName=tDisVehicleMapper.selectByVid(vId);
            double timeSpans = new BigDecimal((float)timeSpan/60).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
            jsonObject.put("enterpriseName",enterpriseName);
            jsonObject.put("platformName",platformName);
            jsonObject.put("vehicleName",vehicleName);
            jsonObject.put("timeSpan",String.valueOf(timeSpans));

        }
        return json;
    }


    @ApiOperation(value = "获取某辆车的超速报警详情")
    @RequestMapping(value = "/overspeed/infoByVidAndDate",method = RequestMethod.GET)
    public JSONObject infoByVidAndDate(Integer[] vehicleIds,String limit,String page,String date){
        Map map=new HashMap();
        map.put("vId",String.valueOf(vehicleIds));//车辆id,多个id以逗号分隔
        map.put("limit",limit);//页面记录数，默认值为10
        map.put("page",page);//页码，默认值为1
        map.put("date",date);//必传 查询日期yyyy-MM-dd
        Set<String> set = map.keySet();
        Iterator<String> it = set.iterator();
        while (it.hasNext()) {
            String str = it.next();
            if(map.get(str)==null || map.get(str) =="null"|| map.get(str)==""){
                map.remove(str);
                set = map.keySet();
                it = set.iterator();
            }
        }
        Map<String,String>headMap=new HashMap<>();
        headMap.put("clientCode",clientCode);
        String url="http://"+Ip+":"+port+"/dis/v1/statistics/overspeed/infoByVidAndDate";
        String result=HttpClientUtils.doGet(url,headMap,map);
        JSONObject json= JSONObject.parseObject(result);
        JSONObject jo=json.getJSONObject("result");
        JSONArray jsonArray=jo.getJSONArray("list");
        if (jsonArray==null){
            return json;
        }
        for (int i = 0; i < jsonArray.size(); i++) {
            JSONObject jsonObject=jsonArray.getJSONObject(i);
            Integer vId=Integer.parseInt(jsonObject.getString("vId"));//车辆id
            Integer pId=Integer.parseInt(jsonObject.getString("pId"));//平台id
            Integer eId=Integer.parseInt(jsonObject.getString("eId"));//企业id
            Integer timeSpan=Integer.parseInt(jsonObject.getString("timeSpan"));//持续时长(min)
            //String enterpriseName=sysEnterpriseMapper.selectByEid(eId);//企业名称
            String enterpriseName=tDisEnterpriseMapper.selectByEid(eId);
            //String platformName=sysUserService.selectBypId(pId);//平台名称
            String platformName=tDisPlatformMapper.selectpId(pId);
            //String vehicleName=pwVehicleMapper.selectByVid(vId);//车辆名称
            String vehicleName=tDisVehicleMapper.selectByVid(vId);
            double timeSpans = new BigDecimal((float)timeSpan/60).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
            jsonObject.put("enterpriseName",enterpriseName);
            jsonObject.put("platformName",platformName);
            jsonObject.put("vehicleName",vehicleName);
            jsonObject.put("timeSpan",String.valueOf(timeSpans));

        }
        return json;
    }


    @ApiOperation(value = "车辆数据合格率统计")
    @RequestMapping(value = "/vehicleDataPassStatistic/info",method = RequestMethod.GET)
    public JSONObject getVehicleDataPassStatistic(String startDate,String endDate,String limit,String page,String eid,String pName,String vNumber,String regionCode){
        if (vNumber!=null && vNumber.length() < 3 && !vNumber.equals("")) {
            String list = "{\"code\":1009,\"msg\":\"请输入车牌号不少于3位\"}";
            return JSONObject.parseObject(list);
        }
        String vIdlist="";
        String pIdList="";
        String vIds=null;
        String pIds=null;
        if (vNumber!=null && vNumber.equals("")==false){
            List<Map> vehicleNumberList=tDisVehicleMapper.selectVehicleId(vNumber.toUpperCase());
            if (vehicleNumberList.size()>0){
                for (int i = 0; i < vehicleNumberList.size(); i++) {
                    vIdlist=vIdlist+vehicleNumberList.get(i).get("vehicle_id")+",";
                }
                vIds=StringUtils.join(vIdlist.split(","),",");
            }else {
                String list="{\"code\":1001,\"msg\":\"接口执行成功\",\"result\":{\"currPage\":1,\"list\":[],\"pageSize\":0,\"totalCount\":0,\"totalPage\":0}}";
                return JSONObject.parseObject(list);
            }
        }
        if (pName!=null && pName.equals("")==false){
            List<Map> pIdsList=tDisPlatformMapper.selectPlatformIdsList(pName);


            if (pIdsList.size()>0){
                for (int i = 0; i < pIdsList.size(); i++) {
                    pIdList=pIdList+pIdsList.get(i).get("platform_id")+",";
                }
                pIds=StringUtils.join(pIdList.split(","),",");
            }else {
                String list="{\"code\":1001,\"msg\":\"接口执行成功\",\"result\":{\"currPage\":1,\"list\":[],\"pageSize\":0,\"totalCount\":0,\"totalPage\":0}}";
                return JSONObject.parseObject(list);
            }
        }
        NumberFormat nf = java.text.NumberFormat.getPercentInstance();
        Map map=new HashMap();
        map.put("startDate",startDate);//必选 开始查询日期yyyy-MM-dd
        map.put("endDate",endDate);//必选 结束查询日期yyyy-MM-dd,查询时间不要超过30天
        map.put("pIds",pIds);//平台id,多个id英文逗号分隔
        map.put("eIds",eid);//企业id,多个id英文逗号分隔
        map.put("vIds",vIds);//车辆id,多个id英文逗号分隔
        map.put("regionCode",regionCode);
        map.put("limit",limit);// 必传页面记录数，默认值为10
        map.put("page",page);//必传 页码，默认为1
        Set<String> set = map.keySet();
        Iterator<String> it = set.iterator();
        while (it.hasNext()) {
            String str = it.next();
            if(map.get(str)==null || map.get(str) =="null"|| map.get(str)==""){
                map.remove(str);
                set = map.keySet();
                it = set.iterator();
            }
        }
        Map<String,String>headMap=new HashMap<>();
        headMap.put("clientCode",clientCode);
        String url="http://"+Ip+":"+port+"/dis/v1/statistics/vehicleDataPassStatistic/info";
        String result=HttpClientUtils.doGet(url,headMap,map);
        JSONObject json= JSONObject.parseObject(result);
        JSONObject jo=json.getJSONObject("result");
        JSONArray jsonArray=jo.getJSONArray("list");
        if (jsonArray==null){
            return json;
        }
        for (int i = 0; i < jsonArray.size(); i++) {
            JSONObject jsonObject=jsonArray.getJSONObject(i);
            Integer vId=Integer.parseInt(jsonObject.getString("vId"));//车辆id
            Integer pId=Integer.parseInt(jsonObject.getString("pId"));//平台id
            Integer eIds=Integer.parseInt(jsonObject.getString("eId"));//企业id
            String passRate=jsonObject.getString("passRate");//数据合格率
            double c=Double.valueOf(passRate);
            String passRates=nf.format(c);//将合格率转成百分数
            String enterpriseName=tDisEnterpriseMapper.selectByEid(eIds);
            String platformName=tDisPlatformMapper.selectpId(pId);
            List<Map<String,Object>>vehicleList=tDisVehicleMapper.selectPNameAndEname(vId);
            String vehicleNumber=null;
            if (vehicleList.size()>0){
                vehicleNumber=String.valueOf(vehicleList.get(0).get("vehicleNumber"));
            }
            jsonObject.put("enterpriseName",enterpriseName);
            jsonObject.put("platformName",platformName);
            jsonObject.put("vehicleName",vehicleNumber);
            jsonObject.put("passRate",passRates);


        }
        return json;
    }


    @ApiOperation(value = "车辆轨迹完整统计")
    @RequestMapping(value = "/vehicleTrackFullStatistic",method = RequestMethod.GET)
    public JSONObject TrackFullStatistic(String startDate,String endDate,String limit,String page,String eid,String pName,String vNumber,String regionCode){
        if (vNumber!=null && vNumber.length() < 3 && !vNumber.equals("")) {
            String list = "{\"code\":1009,\"msg\":\"请输入车牌号不少于3位\"}";
            return JSONObject.parseObject(list);
        }
        String vIdlist="";
        String pIdList="";
        String vIds=null;
        String pIds=null;
        if (vNumber!=null&&vNumber.equals("")==false){
            List<Map> vehicleNumberList=tDisVehicleMapper.selectVehicleId(vNumber.toUpperCase());
            if (vehicleNumberList.size()>0){
                for (int i = 0; i < vehicleNumberList.size(); i++) {
                    vIdlist=vIdlist+vehicleNumberList.get(i).get("vehicle_id")+",";
                }
                vIds=StringUtils.join(vIdlist.split(","),",");
            }else {
                String list="{\"code\":1001,\"msg\":\"接口执行成功\",\"result\":{\"currPage\":1,\"list\":[],\"pageSize\":0,\"totalCount\":0,\"totalPage\":0}}";
                return JSONObject.parseObject(list);
            }
        }
        if (pName!=null&&pName.equals("")==false){
            List<Map> pIdsList=tDisPlatformMapper.selectPlatformIdsList(pName);
            if (pIdsList.size()>0){
                for (int i = 0; i < pIdsList.size(); i++) {
                    pIdList=pIdList+pIdsList.get(i).get("platform_id")+",";
                }
                pIds=StringUtils.join(pIdList.split(","),",");
            }else {
                String list="{\"code\":1001,\"msg\":\"接口执行成功\",\"result\":{\"currPage\":1,\"list\":[],\"pageSize\":0,\"totalCount\":0,\"totalPage\":0}}";
                return JSONObject.parseObject(list);
            }
        }
        NumberFormat nf = java.text.NumberFormat.getPercentInstance();
        Map map=new HashMap();
        map.put("startDate",startDate);//必传 开始查询日期yyyy-MM-dd
        map.put("endDate",endDate);//必传 结束查询日期yyyy-MM-dd
        map.put("vIds",vIds);//车辆id,多个以逗号分隔
        map.put("eIds",eid);//企业id,多个以逗号分隔
        map.put("pIds",pIds);//平台id,多个以逗号分隔
        map.put("regionCode",regionCode);
        map.put("limit",limit);//页面记录数,默认值为10
        map.put("page",page);//页码，默认值为1
        Set<String> set = map.keySet();
        Iterator<String> it = set.iterator();
        while (it.hasNext()) {
            String str = it.next();
            if(map.get(str)==null || map.get(str) =="null"|| map.get(str).equals("")){
                map.remove(str);
                set = map.keySet();
                it = set.iterator();
            }
        }
        Map<String,String>headMap=new HashMap<>();
        headMap.put("clientCode",clientCode);
        String url="http://"+Ip+":"+port+"/dis/v1/statistics/vehicleTrackFullStatistic/info";
        String result=HttpClientUtils.doGet(url,headMap,map);
        JSONObject json= JSONObject.parseObject(result);
        JSONObject jo=json.getJSONObject("result");
        if (jo==null){
            return json;
        }
        JSONArray jsonArray=jo.getJSONArray("list");

        for (int i = 0; i < jsonArray.size(); i++) {
            JSONObject jsonObject=jsonArray.getJSONObject(i);
            Integer vId=Integer.parseInt(jsonObject.getString("vId"));//车辆id
            Integer pId=Integer.parseInt(jsonObject.getString("pId"));//平台id
            Integer eIds=Integer.parseInt(jsonObject.getString("eId"));//企业id
            String trackFullRate=jsonObject.getString("trackFullRate");//数据合格率
            double c=Double.valueOf(trackFullRate);
            String trackFullRates=nf.format(c);//将轨迹完成度转成百分数
            String enterpriseName=tDisEnterpriseMapper.selectByEid(eIds);
            String platformName=tDisPlatformMapper.selectpId(pId);
            List<Map<String,Object>>vehicleList=tDisVehicleMapper.selectPNameAndEname(vId);
            jsonObject.put("enterpriseName",vehicleList.get(0).get("enterpriseName"));
            jsonObject.put("platformName",vehicleList.get(0).get("platformName"));
            jsonObject.put("vehicleName",vehicleList.get(0).get("vehicleNumber"));
            jsonObject.put("trackFullRate",trackFullRates);
        }
        return json;
    }

    @ApiOperation(value = "疲劳驾驶时长统计接口")
    @RequestMapping(value = "/FatigueDrivingStatistic/info",method = RequestMethod.GET)
    public  JSONObject FatigueDrivingStatistic(String startTime, String endTime,String limit,String page,String admdivcode,String eName,String pName,String vNumber){
        String eIdsList="";
        String vIdlist="";
        String pIdList="";
        String eIds=null;
        String vIds=null;
        String pIds=null;
        if (eName!=null && eName.equals("")==false){
            List<Map> eIdsLists = tDisEnterpriseMapper.selectEnterpriseNameList(eName);
            if (eIdsLists.size()>0){
                for (int i = 0; i < eIdsLists.size(); i++) {
                    eIdsList = eIdsList + eIdsLists.get(i).get("enterprise_id")+",";
                }
                eIds=StringUtils.join(eIdsList.split(","),",");
            }else {
                String list="{\"code\":1001,\"msg\":\"接口执行成功\",\"result\":{\"currPage\":1,\"list\":[],\"pageSize\":0,\"totalCount\":0,\"totalPage\":0}}";
                return JSONObject.parseObject(list);
            }
        }
        if (vNumber!=null&&vNumber.equals("")==false){
            List<Map> vehicleNumberList=tDisVehicleMapper.selectVehicleId(vNumber);
            if (vehicleNumberList.size()>0){
                for (int i = 0; i < vehicleNumberList.size(); i++) {
                    vIdlist=vIdlist+vehicleNumberList.get(i).get("vehicle_id")+",";
                }
                vIds=StringUtils.join(vIdlist.split(","),",");
            }else {
                String list="{\"code\":1001,\"msg\":\"接口执行成功\",\"result\":{\"currPage\":1,\"list\":[],\"pageSize\":0,\"totalCount\":0,\"totalPage\":0}}";
                return JSONObject.parseObject(list);
            }
        }
        if (pName!=null&&pName.equals("")==false){
            List<Map> pIdsList=tDisPlatformMapper.selectPlatformIdsList(pName);
            if (pIdsList.size()>0){
                for (int i = 0; i < pIdsList.size(); i++) {
                    pIdList=pIdList+pIdsList.get(i).get("platform_id")+",";
                }
                pIds=StringUtils.join(pIdList.split(","),",");
            }else {
                String list="{\"code\":1001,\"msg\":\"接口执行成功\",\"result\":{\"currPage\":1,\"list\":[],\"pageSize\":0,\"totalCount\":0,\"totalPage\":0}}";
                return JSONObject.parseObject(list);
            }
        }
        NumberFormat nf = java.text.NumberFormat.getPercentInstance();
        Map map=new HashMap();
        map.put("startTime",startTime);//开始时间yyyy-MM-dd HH:mm:ss
        map.put("endTime",endTime);//结束时间yyyy-MM-dd HH:mm:ss
        map.put("pIds",pIds);//平台id,多个id以逗号间隔
        map.put("eIds",eIds);//企业id,多个id以逗号间隔
        map.put("vIds",vIds);//车辆id,多个id以逗号间隔
        map.put("limit",limit);//页面记录数，默认值为10
        map.put("page",page);//页码，默认值为1
        map.put("admdivcode",admdivcode);//必传 行政区划代码
        Set<String> set = map.keySet();
        Iterator<String> it = set.iterator();
        while (it.hasNext()) {
               String str = it.next();
              if(map.get(str)==null || map.get(str) =="null"|| map.get(str)==""){
                map.remove(str);
                set = map.keySet();
                it = set.iterator();
           }
        }

        Map<String,String>headMap=new HashMap<>();
        headMap.put("clientCode",clientCode);
        String url="http://"+Ip+":"+port+"/dis/v1/statistics/fatigueDriving/info";
        String result=HttpClientUtils.doGet(url,headMap,map);
        JSONObject json= JSONObject.parseObject(result);
        JSONObject jo=json.getJSONObject("result");
        JSONArray jsonArray=jo.getJSONArray("list");
        if (jsonArray==null){
            return json;
        }
        for (int i = 0; i < jsonArray.size(); i++) {
            JSONObject jsonObject=jsonArray.getJSONObject(i);
            Integer vId=Integer.parseInt(jsonObject.getString("vId"));//车辆id
            Integer pId=Integer.parseInt(jsonObject.getString("pId"));//平台id
            Integer eId=Integer.parseInt(jsonObject.getString("eId"));//企业id
            Integer timeSpan=Integer.parseInt(jsonObject.getString("timeSpan"));//持续时长(min)
            double timeSpans = new BigDecimal((float)timeSpan/60).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
            //String enterpriseName=sysEnterpriseMapper.selectByEid(eId);//企业名称
            String enterpriseName=tDisEnterpriseMapper.selectByEid(eId);
            //String platformName=sysUserService.selectBypId(pId);//平台名称
            String platformName=tDisPlatformMapper.selectpId(pId);
            //String vehicleName=pwVehicleMapper.selectByVid(vId);//车辆名称
            String vehicleName=tDisVehicleMapper.selectByVid(vId);
            jsonObject.put("enterpriseName",enterpriseName);
            jsonObject.put("platformName",platformName);
            jsonObject.put("vehicleName",vehicleName);
            jsonObject.put("timeSpan",String.valueOf(timeSpans));


        }
        return json;
    }


    @ApiOperation(value = "通过车辆id和日期查询疲劳驾驶信息")
    @RequestMapping(value = "/infoByVidAndDate",method = RequestMethod.GET)
    public JSONObject infoByVidAndDate(Integer vId,String date){
        try {
            Map map=new HashMap();
            map.put("vId",String.valueOf(vId));//必传 车辆id
            map.put("date",date);//必传 查询日期yyyy-MM-dd
            Map<String,String>headMap=new HashMap<>();
            headMap.put("clientCode",clientCode);
            String url="http://"+Ip+":"+port+"/dis/v1/statistics/fatigueDriving/infoByVidAndDate";
            String result=HttpClientUtils.doGet(url,headMap,map);
            JSONObject json= JSONObject.parseObject(result);
            JSONObject jo=json.getJSONObject("result");
            JSONArray jsonArray=jo.getJSONArray("list");
            if (jsonArray==null){
                return json;
            }
            for (int i = 0; i < jsonArray.size(); i++) {
                JSONObject jsonObject=jsonArray.getJSONObject(i);
                Integer vehicelId=Integer.parseInt(jsonObject.getString("vId"));//车辆id
                Integer eId=Integer.parseInt(jsonObject.getString("eId"));//企业id
                //String enterpriseName=sysEnterpriseMapper.selectByEid(eId);//企业名称
                String enterpriseName=tDisEnterpriseMapper.selectByEid(eId);
                //String vehicleName=pwVehicleMapper.selectByVid(vehicelId);//车辆名称
                String vehicleName=tDisVehicleMapper.selectByVid(vehicelId);
                jsonObject.put("enterpriseName",enterpriseName);
                jsonObject.put("vehicleName",vehicleName);
            }
            return json;
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;

    }



    @ApiOperation(value = "车辆动态上线统计")
    @RequestMapping(value = "/realTime/online",method = RequestMethod.POST)
    public JSONObject RealTimeOnline(EncapsulationTired encapsulationTired, String eid, String pName, String vNumber){
        if (vNumber!=null && vNumber.length() < 3 && !vNumber.equals("")) {
            String list = "{\"code\":1009,\"msg\":\"请输入车牌号不少于3位\"}";
            return JSONObject.parseObject(list);
        }
        String pIdList="";
        String pIds=null;
        if (pName!=null&& pName.equals("")==false){
            List<Map> pIdsList=tDisPlatformMapper.selectPlatformIdsList(pName);
            if (pIdsList.size()>0){
                for (int i = 0; i < pIdsList.size(); i++) {
                    pIdList=pIdList+pIdsList.get(i).get("platform_id")+",";
                }
                pIds=StringUtils.join(pIdList.split(","),",");
            }else {
                String list="{\"code\":1001,\"msg\":\"接口执行成功\",\"result\":{\"currPage\":1,\"list\":[],\"pageSize\":0,\"totalCount\":0,\"totalPage\":0}}";
                return JSONObject.parseObject(list);
            }
        }
        Map map=new HashMap();
        //判断车牌号是否为空
        if (vNumber!=null && vNumber.equals("")==false){
            encapsulationTired.setVnumber(vNumber.toUpperCase());
        }else {
            encapsulationTired.setVnumber(null);
        }
        encapsulationTired.setEnterpriseIds(eid);
        encapsulationTired.setPlatformIds(pIds);
        String path="/dis/v1/track/statistics";
        Map<String,String>headMap=new HashMap<>();
        headMap.put("clientCode",clientCode);
        JSONObject jsonString = new JSONObject();
        String body= jsonString.toJSONString(encapsulationTired);
        long start1,end1;
        start1 = System.currentTimeMillis();
        String result=HttpClientUtils.doPostTestThree(path,headMap,map,body);
        end1 = System.currentTimeMillis();
        logger.info("start time:" + start1+ "; end time:" + end1+ "; Run Time:" + (end1 - start1) + "(ms)");
        JSONObject json= JSONObject.parseObject(result);
        JSONObject jo=json.getJSONObject("result");
        if (jo==null){
            return json;
        }
        JSONArray jsonArray=jo.getJSONArray("list");
        if (jsonArray==null){
            return json;
        }
        for (int i = 0; i < jsonArray.size(); i++) {
            JSONObject jsonObject=jsonArray.getJSONObject(i);
            Integer vehicelId=Integer.parseInt(jsonObject.getString("vehicleId"));//车辆id
            Integer eIds=Integer.parseInt(jsonObject.getString("enterpriseId"));//企业id
            Integer pId=Integer.parseInt(jsonObject.getString("platformId"));//平台id
            String start=jsonObject.getString("startTime");//开始时间
            String end=jsonObject.getString("endTime");//结束时间
            //String startTimeNew=GapTime.getGapTime(start);
            //String endTimeNew=GapTime.getGapTime(end);
            String enterpriseName=tDisEnterpriseMapper.selectByEid(eIds);
            String platformName=tDisPlatformMapper.selectpId(pId);
            List<Map<String,Object>>vehicleList=tDisVehicleMapper.selectPNameAndEname(vehicelId);
            String vehicleColor=tDisVehicleMapper.selectVehicleColor(vehicelId);
            String vehicleLicenseColor=disDictionaryMapper.selectVehicleColor(vehicleColor);
            jsonObject.put("startTime",start);
            jsonObject.put("endTime",end);
            if (vehicleList.size()>0){
                jsonObject.put("enterpriseName",vehicleList.get(0).get("enterpriseName"));
                jsonObject.put("platformName",vehicleList.get(0).get("platformName"));
                jsonObject.put("vehicleColor",vehicleLicenseColor);
            }else {
                jsonObject.put("enterpriseName",null);
                jsonObject.put("platformName",null);
                jsonObject.put("vehicleColor",vehicleLicenseColor);
            }

        }
        return json;
    }



    @ApiOperation(value = "无运政车辆统计接口")
    @RequestMapping(value = "/realTime/nonTransport",method = RequestMethod.POST)
    public LayuiTablePagingResult nonTransport(Integer limit,Integer page,String pName,String vNumber,String startTime,String endTime){
      LayuiTablePagingResult result=null;
      try {
          if (vNumber!=null && vNumber.length() < 3 && !vNumber.equals("")) {
              result = new LayuiTablePagingResult();
              result.setCode("1009");
              result.setMsg("请输入车牌号不少于3位");
              return result;
          }
          Integer pageNum=(page-1)*limit;
          List<Map> pIdsList=new ArrayList<>();
          if (pName!=null && pName.equals("")==false){
              pIdsList=tDisPlatformMapper.selectPlatformIdsList(pName);
              if (pIdsList.size()==0){
                  result = new LayuiTablePagingResult();
                  result.setCode("200");
                  result.setMsg("执行成功");
                  result.setCount((long) 0);
                  result.setData(0);
                  Long totalPages = Long.valueOf(0);
                  result.setTotalPages(totalPages);
                  return result;
              }
          }

          SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
          Calendar nowTime = Calendar.getInstance();
          nowTime.add(Calendar.MINUTE, -5);
          String onlineTime=sdf.format(nowTime.getTime());//在线时间:当前时间前五分钟之内
          List<Map<String,Object>>mismatchVehicle=new LinkedList<>();
          if (vNumber!=null){
              vNumber=vNumber.toUpperCase();
          }
          if (pIdsList.size()>0){
              for (int j = 0; j < pIdsList.size(); j++) {
                  Integer pId=Integer.valueOf(String.valueOf(pIdsList.get(j).get("platform_id")));
                  mismatchVehicle=disMismatchVehicleMapper.selectPage(pId,vNumber,pageNum,limit);
              }
          }else {
              mismatchVehicle=disMismatchVehicleMapper.selectPage(null,vNumber,pageNum,limit);
          }
          if (mismatchVehicle.size()==0){
              result = new LayuiTablePagingResult();
              result.setCode(RetCode.SUCCESS.getCode());
              result.setMsg(RetCode.SUCCESS.getMsg());
              result.setCount(Long.valueOf(0));
              result.setData(mismatchVehicle);
              result.setTotalPages(Long.valueOf(0));
              return result;
          }
          for (int i = 0; i < mismatchVehicle.size(); i++) {
              Map map=mismatchVehicle.get(i);
              String online= String.valueOf(map.get("updateDate"));
              if (online.equals("null")){
                  map.put("onlineStatus","离线");
                  continue;
              }
              if (sdf.parse(onlineTime).before(sdf.parse(online))){
                  map.put("onlineStatus","在线");
              }else {
                  map.put("onlineStatus","离线");
              }
          }

          Integer sum;
          if (mismatchVehicle.get(0).get("total")!=null){
              sum= Integer.valueOf(String.valueOf(mismatchVehicle.get(0).get("total")));
          }else {
              sum=0;
          }

          result = new LayuiTablePagingResult();
          result.setCode(RetCode.SUCCESS.getCode());
          result.setMsg(RetCode.SUCCESS.getMsg());
          result.setCount(Long.valueOf(sum));
          result.setData(mismatchVehicle);
          int totalPages = sum / limit;
          if (sum % limit != 0){
              totalPages ++;
          }
          result.setTotalPages(Long.valueOf(totalPages));
      }catch (Exception e){
          e.printStackTrace();
      }
      return result;
    }


    @ApiOperation(value = "车辆报警统计")
    @RequestMapping(value = "/vehicleAlarmStatistic/info",method = RequestMethod.GET)
    public JSONObject vehicleAlarmStatistic(String startTime,String endTime,String limit,String page,String eid,String pName,String vNumber,String regionCode){
        if (vNumber!=null && vNumber.length() < 3 && !vNumber.equals("")) {
            String list = "{\"code\":1009,\"msg\":\"请输入车牌号不少于3位\"}";
            return JSONObject.parseObject(list);
        }
        String vIdlist="";
        String pIdList="";
        String vIds=null;
        String pIds=null;
        if (vNumber!=null && vNumber.equals("")==false){
            List<Map> vehicleNumberList=tDisVehicleMapper.selectVehicleId(vNumber.toUpperCase());
            if (vehicleNumberList.size()>0){
                for (int i = 0; i < vehicleNumberList.size(); i++) {
                    vIdlist=vIdlist+vehicleNumberList.get(i).get("vehicle_id")+",";
                }
                vIds=StringUtils.join(vIdlist.split(","),",");
            }else {
                String list="{\"code\":1001,\"msg\":\"接口执行成功\",\"result\":{\"currPage\":1,\"list\":[],\"pageSize\":0,\"totalCount\":0,\"totalPage\":0}}";
                return JSONObject.parseObject(list);
            }
        }
        if (pName!=null && pName.equals("")==false){
            List<Map> pIdsList=tDisPlatformMapper.selectPlatformIdsList(pName);


            if (pIdsList.size()>0){
                for (int i = 0; i < pIdsList.size(); i++) {
                    pIdList=pIdList+pIdsList.get(i).get("platform_id")+",";
                }
                pIds=StringUtils.join(pIdList.split(","),",");
            }else {
                String list="{\"code\":1001,\"msg\":\"接口执行成功\",\"result\":{\"currPage\":1,\"list\":[],\"pageSize\":0,\"totalCount\":0,\"totalPage\":0}}";
                return JSONObject.parseObject(list);
            }
        }
        Map map=new HashMap();
        map.put("startTime",startTime);//必选 开始查询时间yyyy-MM-dd HH:mm:ss
        map.put("endTime",endTime);//必选 结束查询时间yyyy-MM-dd HH:mm:ss
        map.put("pIds",pIds);//平台id,多个英文逗号分隔
        map.put("regionCode",regionCode);
        map.put("eIds",eid);//企业id,多个英文逗号分隔
        map.put("vIds",vIds);//车辆id,多个英文逗号分隔
        map.put("limit",limit);//页面记录数，默认值10
        map.put("page",page);//页码，默认值1
        Set<String> set = map.keySet();
        Iterator<String> it = set.iterator();
        while (it.hasNext()) {
            String str = it.next();
            if(map.get(str)==null || map.get(str) =="null"|| map.get(str)==""){
                map.remove(str);
                set = map.keySet();
                it = set.iterator();
            }
        }
        Map<String,String>headMap=new HashMap<>();
        headMap.put("clientCode",clientCode);
        String url="http://"+Ip+":"+port+"/dis/v1/statistics/vehicleAlarmStatistic/info";
        String result=HttpClientUtils.doGet(url,headMap,map);
        JSONObject json= JSONObject.parseObject(result);
        JSONObject jo=json.getJSONObject("result");
        JSONArray jsonArray=jo.getJSONArray("list");
        if (jsonArray==null){
            return json;
        }
        for (int i = 0; i < jsonArray.size(); i++) {
            JSONObject jsonObject=jsonArray.getJSONObject(i);
            Integer vId=Integer.parseInt(jsonObject.getString("vId"));//车辆id
            Integer pId=Integer.parseInt(jsonObject.getString("pId"));//平台id
            Integer eIds=Integer.parseInt(jsonObject.getString("eId"));//企业id
            String alarmType=jsonObject.getString("alarmType");//报警原因
            String vehicelColor=tDisVehicleMapper.selectVehicleColor(vId);//车辆颜色
            String vehicleLicenseColor=disDictionaryMapper.selectVehicleColor(vehicelColor);//车牌颜色
            String alarmTypeName=disDictionaryMapper.selectAlarmType(alarmType);
            String enterpriseName=tDisEnterpriseMapper.selectByEid(eIds);
            String platformName=tDisPlatformMapper.selectpId(pId);
            List<Map<String,Object>>vehicleList=tDisVehicleMapper.selectPNameAndEname(vId);
            jsonObject.put("enterpriseName",vehicleList.get(0).get("enterpriseName"));
            jsonObject.put("platformName",vehicleList.get(0).get("platformName"));
            jsonObject.put("vehicleName",vehicleList.get(0).get("vehicleNumber"));
            jsonObject.put("alarmType",alarmTypeName);
            jsonObject.put("vehiclelicenseColor",vehicleLicenseColor);
        }
        return json;
    }


    //===========报警督办============---这个接口不是本平台的
    @RequestMapping(value = "/urgeTodo",method = RequestMethod.POST)
    public JSONObject urgeTodo(String params,String warnSrc,String supervisionLevel,String supervisionID){
        Map map=new HashMap();
        map.put("params",params);//必选
        map.put("warnSrc",warnSrc);//必选
        map.put("supervisionLevel",supervisionLevel);//必选
        map.put("supervisionID",supervisionID);//必选
        Map<String,String>headMap=new HashMap<>();
        headMap.put("clientCode",clientCode);
        String url="http://"+Ip+":"+port+"/dis/v1/platform/urgeTodo";
        String result=HttpClientUtils.doPost(url,headMap,map);
        JSONObject json= JSONObject.parseObject(result);
        return json;
    }



    @ApiOperation(value = "通过车辆id和日期查询夜间禁行报警")
    @RequestMapping(value = "/nightDriving/infoByVidAndDate",method = RequestMethod.GET)
    public JSONObject infoByVidAndDate(String vid,String date,String limit,String page){
        Map map=new HashMap();
        map.put("vId",vid);//必传 车辆ID
        map.put("date",date);//必传 查询日期yyyy-MM-dd
        map.put("limit",limit);//页面记录数，默认值10
        map.put("page",page);//页码，默认值1
        Set<String> set = map.keySet();
        Iterator<String> it = set.iterator();
        while (it.hasNext()) {
            String str = it.next();
            if(map.get(str)==null || map.get(str) =="null"|| map.get(str)==""){
                map.remove(str);
                set = map.keySet();
                it = set.iterator();
            }
        }
        Map<String,String>headMap=new HashMap<>();
        headMap.put("clientCode",clientCode);
        String url="http://"+Ip+":"+port+"/dis/statistics/nightDriving/infoByVidAndDate";
        String result=HttpClientUtils.doGet(url,headMap,map);
        JSONObject json= JSONObject.parseObject(result);
        return json;
    }


    //======经营性企业监控平台&非经营性企业监控平台 在线数量统计==========--这个可能不用
    @RequestMapping(value = "/platform/onlinecount",method = RequestMethod.GET)
    public JSONObject onlinecount(String regionCode,String platformTypes){
        Map map=new HashMap();
        map.put("regionCode",regionCode);//必传 行政区划代码
        map.put("platformTypes",platformTypes);//平台类型,-1所有平台，0地市级政府监管平台，1非经营性企业监控平台，2经营性企业监控平台，3货运服务监控平台,多个类型以英文逗号分隔
        Set<String> set = map.keySet();
        Iterator<String> it = set.iterator();
        while (it.hasNext()) {
            String str = it.next();
            if(map.get(str)==null || map.get(str) =="null"|| map.get(str)==""){
                map.remove(str);
                set = map.keySet();
                it = set.iterator();
            }
        }
        Map<String,String>headMap=new HashMap<>();
        headMap.put("clientCode",clientCode);
        String url="http://"+Ip+":"+port+"/dis/v1/platform/onlinecount";
        String result=HttpClientUtils.doGet(url,headMap,map);
        JSONObject json= JSONObject.parseObject(result);
        return json;
    }




}

































































